// Cao and Prakash 2010

// Load original dataset
insheet using "CP2010 IO Rep Data.csv"

// REPLICATION
summarize
display c(k)
mdesc
tabmiss
codebook year
codebook country

gen log_so2pgppp=ln(so2pgppp)
gen log_so2pgppplg=ln(so2pgppplg)
gen log_bodpgppp=ln(bodpgppp)
gen log_bodpgppplg=ln(bodpgppplg)
gen log_popd=ln(popd)
gen log_tradeopen=ln(tradeopen)
gen log_fuel=ln(fuel)
gen log_so2pg_n_ppp=ln(so2pg_n_ppp)
gen log_so2pg_n_c_ppp=ln(so2pg_n_c_ppp)
gen log_bodpg_n_ppp=ln(bodpg_n_ppp)
gen log_bodpg_n_c_ppp=ln(bodpg_n_c_ppp)
gen log_1=ln(10^6*gdpcoppp/popt)
gen interaction_1=log_1*ln(10^6*gdpcoppp/popt)
gen interaction_2=ln(100*fdi_in_stock/gdpcu+.001)
gen interaction_3=ln(so2pg_n_ppp)*indicself
gen interaction_4=ln(so2pg_n_ppp)*(1-indicself)
gen interaction_5=ln(bodpg_n_ppp)*indicbodself
gen interaction_6=ln(bodpg_n_ppp)*(1-indicbodself)
encode country, generate (cnum)

gen gdppc = exp(log_1)
summarize

// Table 6
// Model 13
reg log_so2pgppp log_so2pgppplg log_1 interaction_1 industry gdpgr log_popd popubpt log_tradeopen interaction_2 log_fuel pol interaction_3 interaction_4 i.year i.cnum
mdesc log_so2pgppp log_so2pgppplg log_1 interaction_1 industry gdpgr log_popd popubpt log_tradeopen interaction_2 log_fuel pol interaction_3 interaction_4 year cnum
codebook year if e(sample)
codebook country if e(sample)

// Model 14
reg log_bodpgppp log_bodpgppplg log_1 interaction_1 industry gdpgr log_popd popubpt log_tradeopen interaction_2 log_fuel pol interaction_5 interaction_6 i.year i.cnum
mdesc log_bodpgppp log_bodpgppplg log_1 interaction_1 industry gdpgr log_popd popubpt log_tradeopen interaction_2 log_fuel pol interaction_5 interaction_6 year cnum
codebook year if e(sample)
codebook country if e(sample)

// IMPUTATION
clear
use "CP2010 IO Imp Data.dta"
summarize

mi import flong, m(imp) id(country year) imp(so2pgppp-interaction_6)

encode country, generate (cnum)

// Table 6
// Model 13
mi estimate, esampvaryok post: reg log_so2pgppp log_so2pgppplg log_1 interaction_1 industry gdpgr log_popd popubpt log_tradeopen interaction_2 log_fuel pol interaction_3 interaction_4 i.year i.cnum

// Model 14
mi estimate, esampvaryok post: reg log_bodpgppp log_bodpgppplg log_1 interaction_1 industry gdpgr log_popd popubpt log_tradeopen interaction_2 log_fuel pol interaction_5 interaction_6 i.year i.cnum
